package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ActivityAward;
import com.sc.nft.entity.CollectionChipInfo;
import com.sc.nft.entity.CollectionChipInfoRecord;
import com.sc.nft.mapper.ActivityAwardMapper;
import com.sc.nft.mapper.CollectionChipInfoRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class CollectionChipInfoRecordDao extends ServiceImpl<CollectionChipInfoRecordMapper, CollectionChipInfoRecord> {

    public Integer countByCollectionInfo(Long collectionChipInfoId) {
        LambdaQueryWrapper<CollectionChipInfoRecord> lambdaQueryWrapper = new LambdaQueryWrapper<CollectionChipInfoRecord>();
        lambdaQueryWrapper.eq(CollectionChipInfoRecord::getCollectionChipInfoId,collectionChipInfoId);
        return count(lambdaQueryWrapper);
    }

    public CollectionChipInfoRecord getNewOneByUserIdAndChipInfoId(Long userId, Long collectionChipInfoId) {
        LambdaQueryWrapper<CollectionChipInfoRecord> lambdaQueryWrapper = new LambdaQueryWrapper<CollectionChipInfoRecord>();
        lambdaQueryWrapper.eq(CollectionChipInfoRecord::getCollectionChipInfoId,collectionChipInfoId);
        lambdaQueryWrapper.eq(CollectionChipInfoRecord::getUserId,userId);
        lambdaQueryWrapper.last("order by id desc limit 1");
        return getOne(lambdaQueryWrapper);
    }

    public Boolean updateReceiveStatusById(Long id, Integer receiveStatus) {
        LambdaUpdateWrapper<CollectionChipInfoRecord> updateWrapper = new LambdaUpdateWrapper<CollectionChipInfoRecord>();
        updateWrapper.eq(CollectionChipInfoRecord::getId,id);
        updateWrapper.set(CollectionChipInfoRecord::getReceiveStatus,receiveStatus);
        return update(updateWrapper);
    }
}
